package com.kzd.sdk.callback;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.webkit.WebResourceRequest;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class KZD_WebViewClient extends WebViewClient {

    private final Context mContext;

    public KZD_WebViewClient(Context context) {
        this.mContext = context;
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
        if (request == null) {
            return false;
        }
        if (android.os.Build.VERSION.SDK_INT <= android.os.Build.VERSION_CODES.LOLLIPOP) {
            return false;
        }
        try {
            String url = request.getUrl().toString();
            if (url.startsWith("https:") || url.startsWith("http:")) {
                return false;
            }
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            mContext.startActivity(intent);
        } catch (Exception e) {
            return false;
        }
        return true;
    }

    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url == null) {
            return false;
        }
        try {
            if (url.startsWith("https:") || url.startsWith("http:")) {
                return false;
            }
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            mContext.startActivity(intent);
        } catch (Exception e) {
            return false;
        }
        return true;
    }
}
